/****************************************************************************
**
**	File Name   : MainDlg.h
**
**	Project     : DatChecker
**
**	Last Updated: $Header: /DatChecker.root/DatChecker/MainDlg.h 5     2/27/04 8:56a Neusel $
**
**	Description : 
**
**		Interface to the CMainDlg class.
**
****************************************************************************/
#ifndef	H_MAINDLG
	#define H_MAINDLG	__TIMESTAMP__

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#	pragma once
#endif

#include "resource.h"
#include "DropFileHandler.h"
#include "WtlEditBrowserCtrl.h"

class CMainDlg :	public CDialogImpl<CMainDlg>,
					public CDialogResize<CMainDlg>,
					public CDropFilesHandler<CMainDlg>,
					public CIdleHandler,
					public CMessageFilter, 
					public CUpdateUI<CMainDlg>
	{
protected:
	
	bool				m_bDescending,
						m_bScanning;
	int					m_nSortedColumn;
	SIZE_T				m_sequence;
	CWtlEditBrowserCtrl	m_ctrlBrowser;

	void				addObject(ObjInfo const &);
	bool				deleteObjFile(ObjInfoPtr);
	void				discardData(void);
	void				removeObject(ObjInfoPtr);
//
//	INLINES
//
	ObjInfoPtr			getSelectedObject(void)
		{
		int				nItem;
		CListViewCtrl	ctrlList( GetDlgItem(IDC_LIST) );

		if (ctrlList.IsWindow() &&
			(nItem = ctrlList.GetSelectedIndex()) >= 0)
			{
			return reinterpret_cast<ObjInfoPtr>( ctrlList.GetItemData(nItem) );
			}
			
		(void) ::MessageBox(m_hWnd, _T("No object selected."), kStrAppTitle,
								MB_OK|MB_ICONASTERISK);
		return NULL;
		}

public:
	enum { IDD = IDD_MAINDLG };
//
//	File Dropping logic
//
	void				EndDropFiles(void)
							{ /* STUB FUNCTION */ }
							
    BOOL				HandleDroppedFile(LPCTSTR);
    
	BOOL				IsReadyForDrop(void)
							{ return m_bScanning ? FALSE : TRUE; }
//
//	UI logic
//
	virtual BOOL		PreTranslateMessage(MSG * pMsg)
							{ return IsDialogMessage(pMsg); }

	virtual BOOL		OnIdle()
							{
							UIUpdateChildWindows();
							UIEnable(ID_CHECK, 
									(m_bScanning || m_ctrlBrowser.GetWindowTextLength() <= 0) ? FALSE : TRUE);
							return FALSE; 
							}
						
						CMainDlg(void) :	m_bDescending(true), 
											m_bScanning(false), 
											m_nSortedColumn(-1), 
											m_sequence(0)
							{ /* STUB CTOR */ }
							
	virtual				~CMainDlg(void)
							{ /* STUB DTOR */ }
/*
**	WTL VooDoo Code
*/
protected:
	static int CALLBACK	fnCmp(LPARAM, LPARAM, LPARAM);

	LRESULT				onBrowse(UINT, WPARAM, LPARAM lParam, BOOL &);
	void				onCheckObjects(void);
	LRESULT				onCommand(WORD, WORD, HWND, BOOL &);
	void				onContextMenu(HWND, CPoint);
	LRESULT				onCopyData(HWND, PCOPYDATASTRUCT);
	LRESULT				onEndScan(UINT, WPARAM, LPARAM lParam, BOOL &);
	LRESULT				onHeaderItemClick(int, LPNMHDR, BOOL &);
	LRESULT				onHeaderDividerDblClick(int, LPNMHDR, BOOL &);
	LRESULT				onItemDblClick(int, LPNMHDR, BOOL &);
	LRESULT				onInitDialog(HWND, LPARAM);
	void				onObjArchive(void);
	void				onObjClone(void);
	void				onObjDelete(void);
	void				onObjRemove(void);
	void				onObjView(void);
	void				onProperties(void);
	LRESULT				onSysCommand(UINT, CPoint);
//
//	INLINES
//
	LRESULT				onBrowserUpdate(UINT, int, HWND) const
							{
							return 0;
							}
	
	void				onDestroy(void)
							{
							discardData();
							SetMsgHandled(FALSE);
							}
/*
**	WTL VooDoo Code
*/
public:
	BEGIN_DLGRESIZE_MAP(CMainDlg)
		DLGRESIZE_CONTROL(IDC_FILE_BROWSER, DLSZ_SIZE_X)
		DLGRESIZE_CONTROL(ID_CHECK, DLSZ_MOVE_X)
		DLGRESIZE_CONTROL(IDC_LIST, DLSZ_SIZE_X|DLSZ_SIZE_Y)
	END_DLGRESIZE_MAP()

	BEGIN_UPDATE_UI_MAP(CMainDlg)
		UPDATE_ELEMENT(ID_CHECK, UPDUI_CHILDWINDOW)
	END_UPDATE_UI_MAP()

	BEGIN_MSG_MAP_EX(CMainDlg)
		MSG_WM_CONTEXTMENU(onContextMenu)
		MSG_WM_COPYDATA(onCopyData)
		MSG_WM_DESTROY(onDestroy)
		MSG_WM_INITDIALOG(onInitDialog)
		MSG_WM_SYSCOMMAND(onSysCommand)
		
		MESSAGE_HANDLER(WMU_BROWSE, onBrowse)
		MESSAGE_HANDLER(WMU_END_SCAN, onEndScan)

		COMMAND_HANDLER_EX(IDC_FILE_BROWSER, EN_UPDATE, onBrowserUpdate)
		
		COMMAND_ID_HANDLER(ID_FILE_DELETE, onCommand)
		COMMAND_ID_HANDLER(ID_OBJ_ARCHIVE, onCommand)
		COMMAND_ID_HANDLER(ID_OBJ_CLONE, onCommand)
		COMMAND_ID_HANDLER(ID_OBJ_REMOVE, onCommand)
		COMMAND_ID_HANDLER(ID_OBJ_VIEW, onCommand)
		COMMAND_ID_HANDLER(ID_PROPERTIES, onCommand)
		COMMAND_ID_HANDLER(ID_CHECK, onCommand)
		COMMAND_ID_HANDLER(IDCANCEL, onCommand)
		COMMAND_ID_HANDLER(IDOK, onCommand)

	    NOTIFY_CODE_HANDLER(HDN_ITEMCLICK, onHeaderItemClick)
	    NOTIFY_CODE_HANDLER(HDN_DIVIDERDBLCLICK, onHeaderDividerDblClick)
		NOTIFY_CODE_HANDLER(NM_DBLCLK, onItemDblClick)		
	    
		REFLECT_NOTIFICATIONS()     
		
		CHAIN_MSG_MAP(CDialogResize<CMainDlg>)
		CHAIN_MSG_MAP(CDropFilesHandler<CMainDlg>) 
	END_MSG_MAP()
	};
#endif	// H_MAINDLG
/****************************************************************************
**
**	$History: MainDlg.h $
 * 
 * *****************  Version 5  *****************
 * User: Neusel       Date: 2/27/04    Time: 8:56a
 * Updated in $/DatChecker.root/DatChecker
 * v1.9 -- Added drag and drop handler.
 * 
 * *****************  Version 4  *****************
 * User: Neusel       Date: 1/21/04    Time: 6:40p
 * Updated in $/DatChecker.root/DatChecker
 * 
 * *****************  Version 3  *****************
 * User: Neusel       Date: 9/08/03    Time: 9:34a
 * Updated in $/DatChecker.root/DatChecker
 * v1.2 -- added ObjData header file and internal checks.
 * 
 * *****************  Version 2  *****************
 * User: Neusel       Date: 8/14/03    Time: 3:59p
 * Updated in $/DatChecker.root/DatChecker
 * Added "Object Clone" and String Table capability.
 * 
 * *****************  Version 1  *****************
 * User: Neusel       Date: 8/14/03    Time: 9:25a
 * Created in $/DatChecker.root/DatChecker
**
**	-------------------------------------------------------------------------
**
**	End of MainDlg.h
**
****************************************************************************/
